//引入数据库
const db = require('../db/index')

//首页信息函数
exports.showIndex = (req, res) => {

    const selectSql = 'SELECT * FROM pub_index';

    db.query(selectSql, (err, results) => {
        if (err) return res.cc(err)
        for (let i = 0; i < results.length; i++) {
            results[i].pub_img = results[i].pub_img.split(',')
        }

        res.send({
            status: 0,
            message: "获取首页所有数据",
            data: results
        })
    })
}

//首页搜索信息函数
exports.searchIndex = (req, res) => {
    // console.log(req.body);

    const selectSql = 'select * from pub_index where pub_des like ?;'

    db.query(selectSql, req.body.value, (err, results) => {
        if (err) return res.cc(err)

        for (let i = 0; i < results.length; i++) {
            results[i].pub_img = results[i].pub_img.split(',')
        }

        res.send({
            status: 0,
            message: "查询成功",
            data: results
        })

    })
}